package com.bdmc.web.controller.task;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.bdmc.common.annotation.RepeatSubmit;
import com.bdmc.common.annotation.Log;
import com.bdmc.common.core.controller.BaseController;
import com.bdmc.common.core.domain.PageQuery;
import com.bdmc.common.core.domain.AjaxResult;
import com.bdmc.common.core.validate.AddGroup;
import com.bdmc.common.core.validate.EditGroup;
import com.bdmc.common.core.validate.QueryGroup;
import com.bdmc.common.enums.BusinessType;
import com.bdmc.common.utils.poi.ExcelUtil;
import com.bdmc.task.domain.vo.TaskPlanDetailVo;
import com.bdmc.task.domain.bo.TaskPlanDetailBo;
import com.bdmc.task.service.ITaskPlanDetailService;
import com.bdmc.common.core.page.TableDataInfo;


/**
 * 每日排班详情控制器
 *
 * @author bdmc
 * @date 2022-03-06
 */
@Validated
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/task/detail")
public class TaskPlanDetailController extends BaseController {

    private final ITaskPlanDetailService iTaskPlanDetailService;

    /**
     * 查询每日排班详情列表
     */
    @SaCheckPermission("task:detail:list")
    @GetMapping("/list")
    public TableDataInfo<TaskPlanDetailVo> list(@Validated(QueryGroup.class) TaskPlanDetailBo bo, PageQuery pageQuery) {
        return iTaskPlanDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出每日排班详情列表
     */
    @SaCheckPermission("task:detail:export")
    @Log(title = "每日排班详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated TaskPlanDetailBo bo, HttpServletResponse response) {
        List<TaskPlanDetailVo> list = iTaskPlanDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "每日排班详情", TaskPlanDetailVo.class, response);
    }

    /**
     * 获取每日排班详情详细信息
     */
    @SaCheckPermission("task:detail:query")
    @GetMapping("/{planDetailId}")
    public AjaxResult<TaskPlanDetailVo> getInfo(@PathVariable("planDetailId") Integer planDetailId) {
        return AjaxResult.success(iTaskPlanDetailService.queryById(planDetailId));
    }

    /**
     * 新增每日排班详情
     */
    @SaCheckPermission("task:detail:add")
    @Log(title = "每日排班详情", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody TaskPlanDetailBo bo) {
        return toAjax(iTaskPlanDetailService.insertByBo(bo));
    }

    /**
     * 修改每日排班详情
     */
    @SaCheckPermission("task:detail:edit")
    @Log(title = "每日排班详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody TaskPlanDetailBo bo) {
        return toAjax(iTaskPlanDetailService.updateByBo(bo));
    }

    /**
     * 删除每日排班详情
     */
    @SaCheckPermission("task:detail:remove")
    @Log(title = "每日排班详情" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{planDetailIds}")
    public AjaxResult<Void> remove(@PathVariable Integer[] planDetailIds) {
        return toAjax(iTaskPlanDetailService.deleteWithValidByIds(Arrays.asList(planDetailIds), true));
    }
}
